package com.gbas.gnet.server;

import com.gbas.gnet.NetObjectNewPing;

class PingALive implements Runnable {
    static final int TIME_SLEEP = 5000;
    private ServerThread papa = null;
    private boolean running = true;

    PingALive(ServerThread papa) {
        this.papa = papa;
        running = true;
    }

    public boolean isRunning() {
        return running;
    }

    public void setRunning(boolean running) {
        this.running = running;
    }

    public void run() {
        while (running) {
            try {
                Thread.sleep(TIME_SLEEP);
                if (papa != null && papa.getClients().size() > 0) {
                    papa.sendToAll(new NetObjectNewPing(System.currentTimeMillis()));
                }
                if (papa != null)
                    papa.pingLaunched(papa.getClients().size());

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

